package cn.mazexal.exambg.controller.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: Mazexal
 * Date: 2021/9/22
 */
@Configuration
public class WebAppConfigurer implements WebMvcConfigurer {
    //用来定位资源路径
    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        String os = System.getProperty("os.name");
        //如果是Windows系统
        if (os.toLowerCase().startsWith("win")) {
            registry.addResourceHandler("/tarotImage/**").addResourceLocations("file:D:/tarotImage/");
            registry.addResourceHandler("/avatars/**").addResourceLocations("file:/avatars/");
            registry.addResourceHandler("/appUpdate/**").addResourceLocations("file:/appUpdate/");
        } else {  //linux 和mac
            registry.addResourceHandler("/tarotImage/**").addResourceLocations("file:/opt/tarotImage/");
            registry.addResourceHandler("/avatars/**").addResourceLocations("file:/opt/avatars/");
            registry.addResourceHandler("/appUpdate/**").addResourceLocations("file:/opt/appUpdate/");
        }

    }

    //拦截器 暂时不是用使用UserFilter
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new UserTokenInterceptor());
    }
}
